package cn.iocoder.yudao.module.cms.benefit.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.api.cms.benefit.dto.BenefitRespDTO;
import cn.iocoder.yudao.module.cms.benefit.bo.BenefitCategoryBO;
import cn.iocoder.yudao.module.cms.benefit.dal.dataobject.BenefitDO;
import cn.iocoder.yudao.module.cms.benefit.service.BenefitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 App - 权益保障", description = "可以用于各种权益及服务保障，如用户权益、店铺服务保障")
@RestController
@RequestMapping("/cms/benefit")
@Validated
public class AppBenefitController {

    @Resource
    private BenefitService benefitService;

    @GetMapping("/all-category")
    @Operation(summary = "已定义的所有种类")
    @PermitAll
    public CommonResult<List<BenefitCategoryBO>> getAllCategory() {
        List<BenefitCategoryBO> allCategory = benefitService.getAllCategory();
        return success(allCategory);
    }

    @GetMapping("/list")
    @Operation(summary = "获得权益保障内容")
    @Parameter(name = "category", description = "种类，如：member_vip_benefit-用户权益、……", required = true, example = "member_vip_benefit")
    @PermitAll
    public CommonResult<List<BenefitRespDTO>> getBenefitList(@RequestParam("category") String category) {
        List<BenefitDO> list = benefitService.getBenefitList(category);
        return success(BeanUtils.toBean(list, BenefitRespDTO.class));
    }

}
